package androidgame.teslawars;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import androidgame.framework.FileIO;

// Loads initial settings, such as if the sound was enabled before and high scores. Additionally could hold AI difficulty levels, levels completed
// etc.
// @author dicarlo2
public class Settings {
    public static boolean soundEnabled = true;
    public final static String file = ".teslawars";
	
	public static void load(FileIO files){
		BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(files.readFile(file)));
            soundEnabled = Boolean.parseBoolean(in.readLine());
        } catch (IOException e) {
        } catch (NumberFormatException e) {
        } finally {
            try {
                if (in != null)
                    in.close();
            } catch (IOException e) {
            }
        }
		
	}
	
	public static void save(FileIO files){
		 BufferedWriter out = null;
	        try {
	            out = new BufferedWriter(new OutputStreamWriter(
	                    files.writeFile(file)));
	            out.write(Boolean.toString(soundEnabled));
	            out.write("\n");
	        } catch (IOException e) {
	        } finally {
	            try {
	                if (out != null)
	                    out.close();
	            } catch (IOException e) {
	            }
	        }
		
	}

}
